package com.yunji.aggregate.convert;

import com.yunji.aggregate.model.vo.base.WalletTurnoverVO;
import com.yunji.common.enums.business.TradeMode;
import com.yunji.common.enums.business.TurnoverStatus;
import com.yunji.common.enums.common.UserType;
import com.yunji.common.model.dto.LoginInfo;
import com.yunji.common.utils.bean.BeanUtils;
import com.yunji.system.context.SystemContext;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author : peter-zhu
 * @date : 2024/12/17 13:57
 * @description : TODO
 **/
public class AggregateDataConvert {

    /**
     * @Title getUserType
     * @Desc 获取用户类型
     * @Date 2024-09-10 14:26:51.339
     * @Return String[] 用户类型数组
     */
    public static String[] getUserType() {
        LoginInfo user = SystemContext.getUser();
        String userType = user.getUserType();
        List<String> list = new ArrayList<>();
        if (BeanUtils.equals(userType, UserType.PLATE.getCode(), UserType.AGENT.getCode())) {
            list.add(UserType.AGENT.getCode());
        }

        if (BeanUtils.equals(userType, UserType.PLATE.getCode(), UserType.AGENT.getCode(), UserType.SITE.getCode())) {
            list.add(UserType.SITE.getCode());
        }

        if (BeanUtils.equals(userType, UserType.STAFF.getCode())) {
            list.add(UserType.STAFF.getCode());
        }
        return list.toArray(new String[0]);
    }

    /**
     * @param list
     * @Title turnoverList
     * @Desc 反参转换流转状态
     * @Date 2024-10-28 17:11:52.902
     */
    public static void turnoverList(List<WalletTurnoverVO> list) {
        for (WalletTurnoverVO vo : list) {
            Integer tradeMode = vo.getTradeMode();
            Integer tradeStatus = vo.getTradeStatus();
            Integer turnoverStatus = null;
            if (Objects.equals(4, tradeStatus)) {
                switch (tradeMode) {
                    case 1:
                        turnoverStatus = TurnoverStatus.PAYOUT_SUCCESS.getCode();
                        break;
                    case 2:
                        turnoverStatus = TurnoverStatus.REFUND_SUCCESS.getCode();
                        break;
                    default:
                        turnoverStatus = TurnoverStatus.TRADE_SUCCESS.getCode();
                }
            } else if (Objects.equals(5, tradeStatus)) {
                if (Objects.equals(TradeMode.PAYOUT.getCode(), tradeMode)) {
                    turnoverStatus = TurnoverStatus.PAYOUT_FAIL.getCode();
                }
                if (Objects.equals(TradeMode.REFUND.getCode(), tradeMode)) {
                    turnoverStatus = TurnoverStatus.REFUND_FAIL.getCode();
                }
            }

            vo.setTurnoverStatus(turnoverStatus);
        }
    }
}
